package com.lottery.ruok.lottrey.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ui.CustomerVideoView;

//import com.danikula.videocache.HttpProxyCacheServer;

/**
 * Created by ASUS on 2017/12/11.
 */

public class VideoActivity extends BaseActivity {
    @BindView(R.id.video)
    CustomerVideoView video;
    @BindView(R.id.skip)
    TextView skip;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_video);
        ButterKnife.bind(this);

        init();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (video.isPlaying()) {
            video.stopPlayback();
        }
    }

    private void init() {
//        RetrofitBase.getRetrofit().create(GetVideoRequest.class)
//                .getResult("ios_video")
//                .enqueue(new Callback<ResponseBody>() {
//                    @Override
//                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//                        try {
//                            String body = response.body().string().replaceAll("\\\\", "").replace("\"{", "{").replace("\"}", "}");
//                            Gson gson = new Gson();
//                            GetVideoResponse getVideoResponse = gson.fromJson(body, GetVideoResponse.class);
//                            if (getVideoResponse != null) {
//                                HttpProxyCacheServer proxy = MyApplication.getProxy(getApplicationContext());
//                                String proxyUrl = proxy.getProxyUrl(getVideoResponse.getData().getValue().getContent());
//                                video.setVideoPath(proxyUrl);
//                                video.start();
//                                video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//                                    @Override
//                                    public void onCompletion(MediaPlayer mediaPlayer) {
//                                        startActivity(new Intent(VideoActivity.this, MainActivity.class));
//
//                                        finish();
//                                    }
//                                });
//                            }
//                        } catch (IOException e) {
//                            e.printStackTrace();
//                        }
//                    }
//
//                    @Override
//                    public void onFailure(Call<ResponseBody> call, Throwable t) {
//                        startActivity(new Intent(VideoActivity.this, MainActivity.class));
//
//                        finish();
//                    }
//                });
    }

    @OnClick(R.id.skip)
    public void onViewClicked() {
        startActivity(new Intent(VideoActivity.this, MainActivity.class));

        finish();
    }
}